#include "pilotController.h"
#include "view/camera/first_person_camera.h"
#include "view/pilotView.h"
#include "view/camera/ortho_camera.h"

PilotController::PilotController(View* view,Model* model)
	:	SceneController(view,model){
}

PilotController::~PilotController(){
}

void PilotController::specKeyboard(int key,int x ,int y){
	SceneController::specKeyboard(key,x,y);

	SceneModel& smodel = dynamic_cast<SceneModel&>(*model);
	PilotView& sview = dynamic_cast<PilotView&>(*view);

	dynamic_cast<FirstPersonCamera&>(sview.getCamera()).moveTo(smodel.getHelicopter().getDimensions().center());
}

void PilotController::keyboard(unsigned char key,float x ,float y){
	SceneController::keyboard(key,x,y);

	PilotView& sview = dynamic_cast<PilotView&>(*view);
	FirstPersonCamera& camera = static_cast<FirstPersonCamera&>(sview.getCamera());
	switch(key){
		case 'q':
			// debo rotar la camara el helicoptero
			camera.rotateLR(Helicopter::zRotationAmount);
			static_cast<OrthoCamera&>(sview.getSubViewCamera()).rotate(Helicopter::zRotationAmount);
			break;
		case 'e':
			camera.rotateLR(-Helicopter::zRotationAmount);
			static_cast<OrthoCamera&>(sview.getSubViewCamera()).rotate(-Helicopter::zRotationAmount);
			break;
	}
}

void PilotController::timer(int value){
	SceneController::timer(value);

	SceneModel& smodel = dynamic_cast<SceneModel&>(*model);
	Helicopter& heli = smodel.getHelicopter();

	if(!(heli.getSpeed()==Point(0,0,0))){
		PilotView& sview = dynamic_cast<PilotView&>(*view);

		FirstPersonCamera& camera = static_cast<FirstPersonCamera&>(sview.getCamera());
		Point center = heli.getDimensions().center();
		camera.moveTo(center);

		center.x3-=2;
		sview.getSubViewCamera().updatePosition(center,Point(0,0,-1),NULL);
	}
}
